using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Practices.CompositeUI.SmartParts;
using NUnit.Framework;
using SCSFContrib.CompositeUI.WPF;

namespace SCSFContrib.CompositeUI.WPF.UnitTest
{
	[TestFixture]
	public sealed class SmartPartPlaceholderTest : UnitTest
	{
		private SmartPartPlaceholder _smartPartPlaceholder;
		private SmartPartPlaceHolderEventArgs _smartPartPlaceHolderEventArgs;

		protected override void SetUpCore()
		{
			base.SetUpCore();
			_smartPartPlaceholder = new SmartPartPlaceholder();
			_smartPartPlaceHolderEventArgs = null;

			_smartPartPlaceholder.SmartPartShown += delegate(object sender, SmartPartPlaceHolderEventArgs e)
			{
				_smartPartPlaceHolderEventArgs = e;
			};
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SmartPart_ShouldThrowIfNull1()
		{
			_smartPartPlaceholder.SmartPart = null;
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void SmartPart_ShouldThrowIfNull2()
		{
			_smartPartPlaceholder.SmartPart = "abc";
			_smartPartPlaceholder.SmartPart = null;
		}

		[Test]
		public void SmartPart_ShouldGetAndSet()
		{
			Assert.IsNull(_smartPartPlaceholder.SmartPart);
			_smartPartPlaceholder.SmartPart = "abc";
			Assert.AreEqual("abc", _smartPartPlaceholder.SmartPart);
			_smartPartPlaceholder.SmartPart = "def";
			Assert.AreEqual("def", _smartPartPlaceholder.SmartPart);
		}

		[Test]
		public void SmartPartName_ShouldGetAndSet()
		{
			Assert.IsNull(_smartPartPlaceholder.SmartPartName);
			_smartPartPlaceholder.SmartPartName = "name";
			Assert.AreEqual("name", _smartPartPlaceholder.SmartPartName);
			_smartPartPlaceholder.SmartPartName = null;
			Assert.IsNull(_smartPartPlaceholder.SmartPartName);
		}

		[Test]
		public void SmartPartShown_ShouldBeRaisedWheneverSmartPartChanges()
		{
			Assert.IsNull(_smartPartPlaceHolderEventArgs);
			_smartPartPlaceholder.SmartPart = "abc";
			Assert.IsNotNull(_smartPartPlaceHolderEventArgs);
			Assert.AreEqual("abc", _smartPartPlaceHolderEventArgs.SmartPart);
			_smartPartPlaceholder.SmartPart = "def";
			Assert.AreEqual("def", _smartPartPlaceHolderEventArgs.SmartPart);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void OnSmartPartShown_ShouldThrowIfEventArgsNull()
		{
			InvokePrivateMethod<object>(_smartPartPlaceholder, "OnSmartPartShown", (SmartPartPlaceHolderEventArgs) null);
		}

		[Test]
		public void OnSmartPartShown_ShouldRaiseSmartPartShown()
		{
			Assert.IsNull(_smartPartPlaceHolderEventArgs);
			SmartPartPlaceHolderEventArgs e = new SmartPartPlaceHolderEventArgs("abc");
			InvokePrivateMethod<object>(_smartPartPlaceholder, "OnSmartPartShown", e);
			Assert.AreSame(e, _smartPartPlaceHolderEventArgs);
		}
	}
}
